﻿class Solution {
public:
	1
		2
		3 int minCost(vector<vector<int>>&costs) {
		4 // dp[i][j] 第i个房⼦刷成第j种颜⾊最⼩花费
			5 int n = costs.size();
		6 vector<vector<int>> dp(n + 1, vector<int>(3));
		7 for (int i = 1; i <= n; i++) {
			8 dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]) + costs[i - 1][0];
			9 dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + costs[i - 1][1];
			10 dp[i][2] = min(dp[i - 1][1], dp[i - 1][0]) + costs[i - 1][2];
			11
		}
		12 return min(dp[n][0], min(dp[n][1], dp[n][2]));
		13
	}
	14
};